/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef _WISHMASTER_THREADSTORAGE_H
#define _WISHMASTER_THREADSTORAGE_H

#include <stdint.h>
#include "sqlite3/sqlite3.h"
#include "sqlite3/CppSQLite3.h"
#include <QObject>
#include <QString>
#include "components/post.h"
#include "components/chan.h"
#include "components/threadptr.h"
#include "misc.h"

namespace Wishmaster
{
	class Thread;
	class Board;
	struct WISHMASTER_EXPORT ThreadEntry
	{
		unsigned int id;
		QString host;
		QString board;
		unsigned int thread_id;
		QString name;
		uint32_t flags;
		int postcount;
		int sortorder;
		QString leader_pic;
	};

	struct WISHMASTER_EXPORT PostEntry
	{
		unsigned int id;
		uint32_t flags;
		QString topic;
		QString text;
		QString thumblink;
		QString piclink;
		unsigned int timestamp;
	};

	class WISHMASTER_EXPORT ThreadStorage : public QObject
	{
		Q_OBJECT
	public:
		virtual ~ThreadStorage() {}

		virtual bool storeThread(const QString& host, const QString& board, Thread* thread) = 0;
		virtual ThreadPtr restoreThread(Board* board, unsigned long thread_id, bool restorePosts = true) = 0;
		virtual bool restoreThread(Board* board, unsigned long thread_id, Thread* thread) = 0;

		virtual void deleteThread(unsigned long id) = 0;
		virtual void setMaxThreads(int max) = 0;

		virtual unsigned long thread(const QString& host, const QString& board, unsigned long thread_id) = 0;
		
		virtual unsigned long setThread(const ThreadEntry& entry) = 0;
		virtual ThreadEntry getThread(unsigned long thread_entry_id) = 0;

		virtual QList<unsigned long> threadList(const QString& host, const QString& board) = 0;
		virtual QList<unsigned long> threadList(const QString& host, const QString& board, uint32_t flags) = 0;

		virtual QList<unsigned long> deleteOldThreads(const QString& host, const QString& board) = 0;

		static const uint32_t ThreadHidden = (1 << 0);
		static const uint32_t ThreadDead = (1 << 1);
		static const uint32_t ThreadInvalid = (1 << 31);
		static const uint32_t ThreadArchived = (1 << 2);
		static const uint32_t ThreadResponded = (1 << 3);

		static const uint32_t PostHidden = (1 << 0);
		static const uint32_t PostThumbLocal = (1 << 1);
		static const uint32_t PostPicLocal = (1 << 2);

		static const unsigned long InvalidThreadId = 0xffffffff;
	};
}

#endif

